﻿// -----------------------------------------------------------------------
// <copyright file="IMessagesContract.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Campfire.Contracts
{
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using DotNet37Signals.Client.Campfire.Models;
    using System;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [ServiceContract]
    public interface IMessagesContract : ICampfireContract
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/room/{roomId}/speak.xml")]
        Message Speak(string roomId, MessageNew request);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/messages/{messageId}/star.xml")]
        void Highlight(string messageId);

        [OperationContract]
        [WebInvoke(Method = "DELETE", UriTemplate = "/messages/{messageId}/star.xml")]
        void RemoveHighlight(string messageId);
    }

    public static class MessagesContractExtensions
    {
        public static Message TextMessage(this IMessagesContract contract, Int64 roomId, string text)
        {
            return contract.Speak(roomId.ToString(), new MessageNew { Type = "TextMessage", Body = text });
        }

        public static Message PasteMessage(this IMessagesContract contract, Int64 roomId, string message)
        {
            return contract.Speak(roomId.ToString(), new MessageNew { Type = "PasteMessage", Body = message });
        }

        public static Message SoundMessage(this IMessagesContract contract, Int64 roomId, MessageSoundType type)
        {
            return contract.Speak(roomId.ToString(), new MessageNew { Type = "SoundMessage", Body = type.ToString() });
        }

        public static Message TweetMessage(this IMessagesContract contract, Int64 roomId, string url)
        {
            return contract.Speak(roomId.ToString(), new MessageNew { Type = "TweetMessage", Body = url });
        }

        public static void Highlight(this IMessagesContract contract, Int64 messageId)
        {
            contract.Highlight(messageId.ToString());
        }

        public static void RemoveHighlight(this IMessagesContract contract, Int64 messageId)
        {
            contract.RemoveHighlight(messageId.ToString());
        }
    }
}
